package com.next

class OptionInstance implements Comparable
{

    String name
    Integer displayOrder = 0
    Boolean selected = false
    static belongsTo = [questionInstance: QuestionInstance]

    static constraints = {
        name maxSize: 64, unique: ['questionInstance']
    }

    static mapping = {
        cache true
    }

    @Override
    int compareTo(Object OptionInstance)
    {

        def option = (OptionInstance) OptionInstance
        if (displayOrder == option.displayOrder)
        {
            return 0
        }
        else if (displayOrder > option.displayOrder)
        {
            return 1
        }
        else
        {
            return -1
        }
    }
}
